package com.yanqu.road.server.cmd.activity.gourdchild;

import com.yanqu.road.pb.activity.GourdChildProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.gourdchild.GourdChildModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_GOURD_CHILD_DRAW_HIDE_BOX_FROM_CROSS, desc = "判断能否抽隐藏款  跨服返回")
public class GourdChildLotteryDrawCmdFromCross extends AbstractCommand {

    boolean canHide = false;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        GourdChildProto.CrossGourdChildDrawHideBoxRespMsg reqMsg = GourdChildProto.CrossGourdChildDrawHideBoxRespMsg.parseFrom(packet.getBytes());
        ret = reqMsg.getRet();
        if (ret == 0) {
            canHide = reqMsg.getIsHide();
        }
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if(ret != 0){
            return;
        }
        ret = player.getModule(GourdChildModule.class).drawBoxFromCross(canHide);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            GourdChildProto.GourdChildLotteryDrawRespMsg.Builder builder = GourdChildProto.GourdChildLotteryDrawRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_GOURD_CHILD_LOTTERY_DRAW, builder);
        }
    }
}
